--[[	$Id: autoPet.lua 3511 2013-08-21 13:54:00Z sdkyron@gmail.com $	]]

local _, caelCore = ...

caelCore.autopet = caelCore.createModule("AutoPet")

-- Auto summon a mini pet

local Summon = function()
	local isActive = C_PetJournal.GetSummonedPetGUID()

	if not isActive then
		local petGUID = caelLib.myChars and "0x0000000001A80934" or "0x0000000001720E15"
			-- Son of Animus "0x0000000001A80934"
			-- Eye of the Legion "0x0000000001A6CA7E"
			-- Direhorn Runt "0x0000000001720E15"
			-- Mr. Bigglesworth "0x00000000015AFE45"
			-- Blighthawk "0x00000000012FD1C6"
			-- Corefire Imp "0x00000000013E0B6F"
			-- Curious Wolvar Pup "0x00000000005ef593"
			-- Giant Bone Spider "0x000000000131473E"
			-- Gilnean Raven "0x0000000001274163"
			-- Pandaren Monk "0x000000000068D0C0"
			-- Spirit of Summer  "0x00000000005ef562"
			-- Whiskers the Rat "0x00000000005EF560"
			-- Worg Pup "0x0000000000B55771"

		if petGUID == isActive then return end

		if petGUID
			and not UnitAffectingCombat("player")
			and not IsMounted() and not IsFlying() and not UnitHasVehicleUI("player")
			and not IsStealthed() and not UnitIsGhost("player")
			and not UnitAura("player", GetSpellInfo(51755), nil, "HELPFUL") -- Camouflage
			and not UnitAura("player", GetSpellInfo(32612), nil, "HELPFUL") -- Invisibility
		then
			C_PetJournal.SummonPetByGUID(petGUID)
		end
	end
end

caelCore.autopet:RegisterEvent("PET_JOURNAL_LIST_UPDATE")
caelCore.autopet:SetScript("OnEvent", function(self, event)
	if event == "PET_JOURNAL_LIST_UPDATE" then
		Summon()
	end
end)

hooksecurefunc("ToggleAutoRun", Summon)
hooksecurefunc("MoveForwardStart", Summon)